/*
 *
 * Copyright(c) TODO
 * licensing@realtor.org
 * http://www.realtor.org/license
 */

Ext.onReady(function()
{
	Ext.QuickTips.init();

	var frm_login;

	var fn_login = function()
	{
		frm_login.getForm().submit(
		{
			waitMsg : 'Logging in...',
			success : function()
			{
				document.location = AD.Globals.URL_AD;
			},
			failure : function(q, a)
			{
				var r = Ext.util.JSON.decode(a.response.responseText);
				Ext.MessageBox.alert('Unable to login', r.msg);
			}
		});
	};

	var cb_mls = make_cb('MLS System', 'mls_system', AD.Data.mls_store, 'MN_Minnesota');

	frm_login = new Ext.FormPanel(
	{
		labelWidth : 95,
		url : AD.Globals.URL_session + 'login',
		frame : true,
		title : 'Please enter your RETS Credentials',
		width : 350,
		timeout : 300,
		defaults : {width : 230},
		defaultType : 'textfield',
		items : [
			{fieldLabel : 'Username', name : 'user', value : ''},
			{fieldLabel : 'Password', name : 'pwd',  value : '', inputType : 'password'},
			cb_mls
		],

		buttons : [	{text : 'Login', handler : fn_login}]
	});

	frm_login.render('div_login');
});
